package com.qige.homework;

import java.util.Calendar;

public class homework5 {
    public static void main(String[] args) {
        int year = 2023; // 指定年份
        int month = 7;   // 指定月份（1-12）
        printMonthCalendar(year, month);
    }
    public static void printMonthCalendar(int year, int month) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(year, month - 1, 1); // 设置年份和月份，注意月份是从0开始的

        int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);

        // 打印日历标题
        System.out.println("日\t一\t二\t三\t四\t五\t六");

        // 打印空格以对齐第一天
        for (int i = 1; i < dayOfWeek; i++) {
            System.out.print("\t");
        }

        // 打印每一天
        for (int day = 1; day <= daysInMonth; day++) {
            System.out.print(day + "\t");
            if ((day + dayOfWeek - 1) % 7 == 0) {
                System.out.println(); // 换行每七天
            }
        }
    }
}
